﻿Imports System.Data.SqlClient
Imports SIREntities
Public Class clsUsuario

  Private cnDB As SqlConnection

  Public Sub New(ByVal psConnectString As String)
    cnDB = New SqlConnection(psConnectString)
  End Sub

  Public Function IngresoSistema(ByVal pvLogUsu As String, ByVal pvPasUsu As String) As clsUsuarioBE
    Dim oUsuario As New clsUsuarioBE
    Dim sqlCmd As New SqlClient.SqlCommand
    Dim oSqlda As SqlDataReader
    Try
      sqlCmd.Connection = cnDB
      sqlCmd.CommandType = CommandType.StoredProcedure
      sqlCmd.CommandText = "spIngresoSistema"
      sqlCmd.Parameters.Add("@pvLogUsu", SqlDbType.VarChar, 20).Value = pvLogUsu
      sqlCmd.Parameters.Add("@pvPasUsu", SqlDbType.VarChar, 20).Value = pvPasUsu
      cnDB.Open()

      oSqlda = sqlCmd.ExecuteReader

      If oSqlda.Read Then
        oUsuario.iCodUsu = oSqlda("iCodUsu")
        oUsuario.vLogUsu = oSqlda("vLogUsu")
        oUsuario.vDocumento = oSqlda("vDocumento")
        oUsuario.vNomUsu = oSqlda("vNomUsu")
      End If

      oSqlda.Dispose()

      Return oUsuario

    Catch ex As Exception
      Throw
    Finally
      If cnDB.State = ConnectionState.Open Then cnDB.Close()
    End Try
  End Function
End Class
